home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk120 / mrcat / readme < prev    next >
Text File  |  1995-03-19  |  3KB  |  78 lines

  1.  
  2. This posting contains the following:
  3.  
  4.     - FileScan.c/h: stdio-based filename list expansion/sort package
  5.  
  6.     - ArpFileScan.c/h: ARP-based filename list expansion/sort package
  7.  
  8.     - MRCat: A "cat" program which uses ArpFileScan or FileScan
  9.  
  10.  
  11. This  is another one of those "Anybody could have written it so why don't I
  12. have  one?"  packages.  It was trivial to write but useful enough to share.
  13. I've  recently  shifted my Usenet source/binary archive activities from the
  14. UnixPC  at  work  to  my  Amiga.   As  you're aware, many of these postings
  15. consist  of  groups  of  similarly  named  files  which, when catenated and
  16. uudecoded,  produce  (most  times) something useful - usually a Zoo archive
  17. full  of  goodies.  Some of these postings come in many parts which have to
  18. be  joined  in  a specific sequence.  If you're using a shell which expands
  19. wildcard  file  specifications  and  sorts the expanded list, more power to
  20. ya'!   I  don't.  I thought it might be nice to have a "cat" which would do
  21. this  for  me.   I  further realized that I frequently port Unix code which
  22. needs  to  do  this  sort  of  thing.   How  about a package to expand/sort
  23. filename lists which is easy to incorporate into foreign code?
  24.  
  25. I've  provided  a  "standard  I/O" version, called FileScan, which uses the
  26. Aztec  scdir() function as its file scanner.  Since I do a lot of ARP-based
  27. stuff,  I  then  cooked up ArpFileScan which uses FindFirst()/FindNext() to
  28. accomplish  the same thing.  The ARP version is fully reentrant.  The stdio
  29. version would be reentrant if scdir() was.
  30.  
  31. You pass each of these a pointer to a list of strings (char *[] or char **,
  32. usually  the  tail end of your program parameter list), a string count, the
  33. address of an integer (new count) and a boolean which specifies if you want
  34. the  list  sorted.   You get back an expanded filename list (char ** again)
  35. and  the new file name count.  In both versions, the list is allocated from
  36. tracked memory which will be freed when the program exits.  Example:
  37.  
  38. main(int argc, char **argv)
  39. {
  40.     int     argn = 1;
  41.     char    **fileList;
  42.     int     fileCount;
  43.     int     fileIndex;
  44.     char    *theFile;
  45.  
  46.     ...process "-" options, incrementing argn along the way...
  47.  
  48.     fileList = FileScan(&argv[argn], argc-argn, &fileCount, 1);
  49.  
  50.     if (fileList) 
  51.         for (fileIndex = 0; fileIndex < fileCount; ++fileIndex) {
  52.             theFile = fileList[fileIndex];
  53.             ...do stuff to/with theFile...   
  54.         }
  55.     ...        
  56.  
  57. MRCat  will  catenate any file(s) or standard input to standard output.  It
  58. treats  each  filename  parameter  as  a group of 1 or more filenames.  The
  59. order of the basic parameters is not changed, so
  60.  
  61.     MRCat c b a
  62.  
  63. will copy the files in c, b, a order. However,
  64.  
  65.     MRCat c* b* a
  66.  
  67. Will copy c1..cn in sorted order, then b1..bn, then a.
  68.  
  69. I  chose  a  buffer  size of 32K for MRCat.  This should minimize thrashing
  70. while  keeping  memory requirements reasonable.  This is contributed to the
  71. public  domain.   You are free to do anything with the enclosed code - just
  72. don't hurt yourself :-).
  73.  
  74.  
  75. Mark Rinfret, 03/11/90
  76.  
  77.  
  78.